<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">// Copyright 2011 Bryan McKelvey, MIT License</span><span class="WHIT">
<span class='line'>  2</span> 
<span class='line'>  3</span> </span><span class="COMM">/**
<span class='line'>  4</span>  * @fileoverview Bookmark sync functionality
<span class='line'>  5</span>  * @author bryan.mckelvey@gmail.com (McKelvey Bryan)
<span class='line'>  6</span>  */</span><span class="WHIT">
<span class='line'>  7</span> 
<span class='line'>  8</span> </span><span class="COMM">/**
<span class='line'>  9</span>  * This singleton contains all the methods used to sync local storage
<span class='line'> 10</span>  * information within the Other Bookmarks folder
<span class='line'> 11</span>  * @constructor
<span class='line'> 12</span>  */</span><span class="WHIT">
<span class='line'> 13</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">Sync</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 14</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 15</span> 	 * The name of the bookmark
<span class='line'> 16</span> 	 * @const
<span class='line'> 17</span> 	 * @type string
<span class='line'> 18</span> 	 */</span><span class="WHIT">
<span class='line'> 19</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">BOOKMARK_NAME</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'Prisma Quotes Data'</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 20</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 21</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 22</span> 	 * The base URL for the bookmark
<span class='line'> 23</span> 	 * @const
<span class='line'> 24</span> 	 * @type string
<span class='line'> 25</span> 	 */</span><span class="WHIT">
<span class='line'> 26</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">BOOKMARK_URL</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="STRN">'http://prismaquotes/?data='</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 27</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 28</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 29</span> 	 * The main bookmark tree index
<span class='line'> 30</span> 	 * @const
<span class='line'> 31</span> 	 * @type number
<span class='line'> 32</span> 	 */</span><span class="WHIT">
<span class='line'> 33</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MAIN_TREE_ID</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 34</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 35</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 36</span> 	 * Within the main tree, the Other Bookmarks folder is always given an index
<span class='line'> 37</span> 	 * of 1
<span class='line'> 38</span> 	 * @const
<span class='line'> 39</span> 	 * @type number
<span class='line'> 40</span> 	 */</span><span class="WHIT">
<span class='line'> 41</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">OTHER_BOOKMARKS_ID</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 42</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 43</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 44</span> 	 * A BookmarkTreeNode object that contains information on the bookmark node
<span class='line'> 45</span> 	 * being used for syncing
<span class='line'> 46</span> 	 * @type object
<span class='line'> 47</span> 	 */</span><span class="WHIT">
<span class='line'> 48</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">syncNode</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 49</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 50</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 51</span> 	 * Whether currently syncing, to avoid event listeners from triggering tons
<span class='line'> 52</span> 	 * of events
<span class='line'> 53</span> 	 * @type boolean
<span class='line'> 54</span> 	 */</span><span class="WHIT">
<span class='line'> 55</span> </span><span class="WHIT">	</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">syncing</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 56</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 57</span> </span><span class="WHIT">	</span><span class="COMM">/**
<span class='line'> 58</span> 	 * Determines the bookmark ID to sync with, creating one if necessary
<span class='line'> 59</span> 	 * @param {function} callback
<span class='line'> 60</span> 	 * @return The current object
<span class='line'> 61</span> 	 * @type Sync
<span class='line'> 62</span> 	 */</span><span class="WHIT">
<span class='line'> 63</span> </span><span class="WHIT">	</span><span class="KEYW">function</span><span class="WHIT"> </span><span class="NAME">getSyncId</span><span class="PUNC">(</span><span class="NAME">callback</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 64</span> </span><span class="WHIT">	  </span><span class="NAME">chrome.bookmarks.getTree</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">tree</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 65</span> </span><span class="WHIT">	    </span><span class="NAME">chrome.bookmarks.search</span><span class="PUNC">(</span><span class="NAME">BOOKMARK_NAME</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">node</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 66</span> </span><span class="WHIT">	      </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">node.length</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 67</span> </span><span class="WHIT">					</span><span class="COMM">// Create a bookmark if one doesn't already exist</span><span class="WHIT">
<span class='line'> 68</span> </span><span class="WHIT">					</span><span class="NAME">syncing</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 69</span> </span><span class="WHIT">	        </span><span class="NAME">chrome.bookmarks.create</span><span class="PUNC">(</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 70</span> </span><span class="WHIT">	          </span><span class="NAME">parentId</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">tree</span><span class="PUNC">[</span><span class="NAME">MAIN_TREE_ID</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">children</span><span class="PUNC">[</span><span class="NAME">OTHER_BOOKMARKS_ID</span><span class="PUNC">]</span><span class="PUNC">.</span><span class="NAME">id</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 71</span> </span><span class="WHIT">	          </span><span class="NAME">title</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">BOOKMARK_NAME</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 72</span> </span><span class="WHIT">	          </span><span class="NAME">url</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">BOOKMARK_URL</span><span class="WHIT">
<span class='line'> 73</span> </span><span class="WHIT">	        </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">result</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 74</span> </span><span class="WHIT">						</span><span class="NAME">syncNode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">result</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 75</span> </span><span class="WHIT">						</span><span class="NAME">Sync.save</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="WHIT">						</span><span class="NAME">syncing</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT">						</span><span class="NAME">callback</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT">					</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 79</span> </span><span class="WHIT">	      </span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT">					</span><span class="NAME">syncNode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">node</span><span class="PUNC">[</span><span class="NUMB">0</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT">					</span><span class="NAME">callback</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT">	      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT">	    </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">		</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">	</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">	</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">		</span><span class="COMM">/**
<span class='line'> 90</span> 		 * Returns the ID associated with the sync bookmark node
<span class='line'> 91</span> 		 * @return {number} The ID number for the bookmark we're syncing with
<span class='line'> 92</span> 		 */</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">		</span><span class="NAME">id</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT">			</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">syncNode.id</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 96</span> </span><span class="WHIT">		</span><span class="WHIT">
<span class='line'> 97</span> </span><span class="WHIT">		</span><span class="COMM">/**
<span class='line'> 98</span> 		 * Arms all of the events that will trigger a reload
<span class='line'> 99</span> 		 * @return The current object
<span class='line'>100</span> 		 * @type Sync
<span class='line'>101</span> 		 */</span><span class="WHIT">
<span class='line'>102</span> </span><span class="WHIT">		</span><span class="NAME">initialize</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>103</span> </span><span class="WHIT">			</span><span class="COMM">// There's probably a slight performance hit or something from monitoring</span><span class="WHIT">
<span class='line'>104</span> </span><span class="WHIT">			</span><span class="COMM">// changes in bookmarks, but this way we don't have to use a bunch of</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT">			</span><span class="COMM">// callbacks when saving from the options screen</span><span class="WHIT">
<span class='line'>106</span> </span><span class="WHIT">			</span><span class="NAME">getSyncId</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>107</span> </span><span class="WHIT">				</span><span class="COMM">// Don't start listening for events until we have the right bookmark</span><span class="WHIT">
<span class='line'>108</span> </span><span class="WHIT">				</span><span class="NAME">Sync.listen</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>109</span> </span><span class="WHIT">				</span><span class="WHIT">
<span class='line'>110</span> </span><span class="WHIT">				</span><span class="COMM">// Probably overkill, but this is just to make sure we don't miss any</span><span class="WHIT">
<span class='line'>111</span> </span><span class="WHIT">				</span><span class="COMM">// sync events prior to figuring out the bookmark node ID</span><span class="WHIT">
<span class='line'>112</span> </span><span class="WHIT">				</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Settings.lastSync</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">syncNode.dateAdded</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>113</span> </span><span class="WHIT">					</span><span class="NAME">Sync.load</span><span class="PUNC">(</span><span class="NAME">syncNode.id</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>114</span> </span><span class="WHIT">				</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>115</span> </span><span class="WHIT">			</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT">			</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>118</span> 
<span class='line'>119</span> </span><span class="WHIT">		</span><span class="COMM">/**
<span class='line'>120</span> 		 * Attaches and detaches event listeners
<span class='line'>121</span> 		 * @param {boolean} toggle Whether to add or remove listeners, defaulting
<span class='line'>122</span> 		 * to true
<span class='line'>123</span> 		 * @return The current object
<span class='line'>124</span> 		 * @type Sync
<span class='line'>125</span> 		 */</span><span class="WHIT">
<span class='line'>126</span> </span><span class="WHIT">		</span><span class="NAME">listen</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">toggle</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT">			</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">toggle</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="NAME">undefined</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">toggle</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT">				</span><span class="NAME">chrome.bookmarks.onChanged.addListener</span><span class="PUNC">(</span><span class="NAME">Sync.load</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>129</span> </span><span class="WHIT">				</span><span class="NAME">chrome.bookmarks.onCreated.addListener</span><span class="PUNC">(</span><span class="NAME">Sync.load</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT">				</span><span class="NAME">chrome.bookmarks.onImportEnded.addListener</span><span class="PUNC">(</span><span class="NAME">Sync.load</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>131</span> </span><span class="WHIT">				</span><span class="NAME">chrome.bookmarks.onRemoved.addListener</span><span class="PUNC">(</span><span class="NAME">Sync.load</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>132</span> </span><span class="WHIT">			</span><span class="PUNC">}</span><span class="WHIT"> </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>133</span> </span><span class="WHIT">				</span><span class="NAME">chrome.bookmarks.onChanged.removeListener</span><span class="PUNC">(</span><span class="NAME">Sync.load</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>134</span> </span><span class="WHIT">				</span><span class="NAME">chrome.bookmarks.onCreated.removeListener</span><span class="PUNC">(</span><span class="NAME">Sync.load</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>135</span> </span><span class="WHIT">				</span><span class="NAME">chrome.bookmarks.onImportEnded.removeListener</span><span class="PUNC">(</span><span class="NAME">Sync.load</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>136</span> </span><span class="WHIT">				</span><span class="NAME">chrome.bookmarks.onRemoved.removeListener</span><span class="PUNC">(</span><span class="NAME">Sync.load</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>137</span> </span><span class="WHIT">			</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>138</span> </span><span class="WHIT">			</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>139</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>140</span> 
<span class='line'>141</span> </span><span class="WHIT">		</span><span class="COMM">/**
<span class='line'>142</span> 		 * Loads information from bookmark
<span class='line'>143</span> 		 * @return {Sync} The current object
<span class='line'>144</span> 		 */</span><span class="WHIT">
<span class='line'>145</span> </span><span class="WHIT">		</span><span class="NAME">load</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">id</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT">			</span><span class="COMM">// Only run if not already syncing and ID of changed bookmark is equal to</span><span class="WHIT">
<span class='line'>147</span> </span><span class="WHIT">			</span><span class="COMM">// that of the bookmark we're syncing with </span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT">			</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">Settings.sync</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">syncing</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">syncNode.id</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="NAME">id</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>149</span> </span><span class="WHIT">				</span><span class="KEYW">try</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>150</span> </span><span class="WHIT">					</span><span class="COMM">// The old node gets deleted, so we have to find the new one that's</span><span class="WHIT">
<span class='line'>151</span> </span><span class="WHIT">					</span><span class="COMM">// replaced it</span><span class="WHIT">
<span class='line'>152</span> </span><span class="WHIT">					</span><span class="NAME">getSyncId</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>153</span> </span><span class="WHIT">						</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">JSON.parse</span><span class="PUNC">(</span><span class="NAME">unescape</span><span class="PUNC">(</span><span class="NAME">syncNode.url.replace</span><span class="PUNC">(</span><span class="NAME">BOOKMARK_URL</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>154</span> </span><span class="WHIT">						</span><span class="NAME">$.each</span><span class="PUNC">(</span><span class="NAME">data</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">key</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>155</span> </span><span class="WHIT">							</span><span class="NAME">localStorage</span><span class="PUNC">[</span><span class="NAME">key</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">value</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>156</span> </span><span class="WHIT">						</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>157</span> </span><span class="WHIT">						</span><span class="NAME">window.location.reload</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>158</span> </span><span class="WHIT">					</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>159</span> </span><span class="WHIT">				</span><span class="PUNC">}</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>160</span> </span><span class="WHIT">				</span><span class="KEYW">catch</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>161</span> </span><span class="WHIT">					</span><span class="COMM">// error handling</span><span class="WHIT">
<span class='line'>162</span> </span><span class="WHIT">				</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>163</span> </span><span class="WHIT">			</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>164</span> </span><span class="WHIT">			</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>165</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>166</span> 
<span class='line'>167</span> </span><span class="WHIT">		</span><span class="NAME">overwrite</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>168</span> </span><span class="WHIT">			</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">data</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">JSON.parse</span><span class="PUNC">(</span><span class="NAME">unescape</span><span class="PUNC">(</span><span class="NAME">syncNode.url.replace</span><span class="PUNC">(</span><span class="NAME">BOOKMARK_URL</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">''</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT">			</span><span class="NAME">alert</span><span class="PUNC">(</span><span class="NAME">JSON.parse</span><span class="PUNC">(</span><span class="NAME">data.lastSync</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">', '</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">Settings.lastSync</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="STRN">', '</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">JSON.parse</span><span class="PUNC">(</span><span class="NAME">data.lastSync</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">Settings.lastSync</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT">			</span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">JSON.parse</span><span class="PUNC">(</span><span class="NAME">data.lastSync</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">Settings.lastSync</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>171</span> </span><span class="WHIT">				</span><span class="KEYW">for</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">key</span><span class="WHIT"> </span><span class="KEYW">in</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>172</span> </span><span class="WHIT">					</span><span class="NAME">localStorage</span><span class="PUNC">[</span><span class="NAME">key</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">data</span><span class="PUNC">[</span><span class="NAME">key</span><span class="PUNC">]</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>173</span> </span><span class="WHIT">				</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>174</span> </span><span class="WHIT">				</span><span class="NAME">alert</span><span class="PUNC">(</span><span class="STRN">'reload time'</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>175</span> </span><span class="WHIT">				</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">d</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Date</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>176</span> </span><span class="WHIT">				</span><span class="NAME">Settings.lastSync</span><span class="PUNC">(</span><span class="NAME">d.getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>177</span> </span><span class="WHIT">				</span><span class="NAME">window.location.reload</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>178</span> </span><span class="WHIT">			</span><span class="PUNC">}</span><span class="WHIT">			</span><span class="WHIT">
<span class='line'>179</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>180</span> 
<span class='line'>181</span> </span><span class="WHIT">		</span><span class="COMM">/**
<span class='line'>182</span> 		 * Saves local storage to bookmark
<span class='line'>183</span> 		 * @return The current object
<span class='line'>184</span> 		 * @type Sync
<span class='line'>185</span> 		 */</span><span class="WHIT">
<span class='line'>186</span> </span><span class="WHIT">		</span><span class="NAME">save</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>187</span> </span><span class="WHIT">			</span><span class="COMM">// Saves regardless of whether sync is on or not. This is to avoid</span><span class="WHIT">
<span class='line'>188</span> </span><span class="WHIT">			</span><span class="COMM">// overwriting everything with some old bookmark if sync gets turned on.</span><span class="WHIT">
<span class='line'>189</span> </span><span class="WHIT">			</span><span class="COMM">// This is probably not ever an issue, but I'll get my bearings first.</span><span class="WHIT">
<span class='line'>190</span> </span><span class="WHIT">			</span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">d</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Date</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>191</span> </span><span class="WHIT">			</span><span class="NAME">syncing</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>192</span> </span><span class="WHIT">			</span><span class="NAME">Settings.lastSync</span><span class="PUNC">(</span><span class="NAME">d.getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>193</span> </span><span class="WHIT">      </span><span class="NAME">chrome.bookmarks.update</span><span class="PUNC">(</span><span class="NAME">syncNode.id</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>194</span> </span><span class="WHIT">        </span><span class="NAME">url</span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">BOOKMARK_URL</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">JSON.stringify</span><span class="PUNC">(</span><span class="NAME">localStorage</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>195</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">result</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>196</span> </span><span class="WHIT">				</span><span class="NAME">syncing</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>197</span> </span><span class="WHIT">			</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>198</span> </span><span class="WHIT">			</span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">this</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>199</span> </span><span class="WHIT">		</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>200</span> </span><span class="WHIT">	</span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>201</span> </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>202</span> 
<span class='line'>203</span> </span><span class="NAME">Sync.initialize</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>